package com.starpl.mobile.android.monthunsae.november.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.starpl.mobile.android.monthunsae.november.R;
import com.starpl.mobile.android.monthunsae.november.handler.CommunityCommentListHandler;
import com.starpl.mobile.android.platform.common.base.BaseActivity;
import com.starpl.mobile.android.platform.component.StarplListView;


/**
 * 리스트뷰에서 댓글을 선택하였을 경우 보여주는 엑티비티
 * 
 * @author 박우람, 우연화
 * @since 2011.03.17
 */
public class CommunityCommentActivity extends BaseActivity implements OnClickListener
{
	private CommunityCommentListHandler mCommentListHandler;
	private StarplListView mSlvComment;
	
	private int mKeywordIdx;
	
	/* (non-Javadoc)
	 * @see com.starpl.platform.common.base.BaseActivity#onCreate(android.os.Bundle)
	 */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.community_comment_activity);
		
		LinearLayout llCommentLayout = (LinearLayout) findViewById(R.id.community_comment_activity_ll_listview);
		TextView tvCommunityName = (TextView)findViewById(R.id.community_comment_activity_tv_community);
		tvCommunityName.setOnClickListener(this);
		
		String userId = getIntent().getStringExtra("userId");
		int userIdx = getIntent().getIntExtra("userIdx", 0);
		int postIdx = getIntent().getIntExtra("postIdx", 0);
		mKeywordIdx = getIntent().getIntExtra("keywordIdx", 0);
		
		boolean isBehindStory = getIntent().getBooleanExtra("isBehindStory", false);
		
		// 뒷담화 커뮤니티에서 넘어온 대상커뮤니티 글인지 아닌지 확인한다.
		if(isBehindStory)
		{
			tvCommunityName.setVisibility(TextView.VISIBLE);
			tvCommunityName.setText(getIntent().getStringExtra("keywordName")+ " 커뮤니티");
		}
		else
		{
			tvCommunityName.setVisibility(TextView.GONE);
		}

		mCommentListHandler = new CommunityCommentListHandler(this, userId, userIdx, postIdx, mKeywordIdx);
		mSlvComment = new StarplListView(mCommentListHandler);
		llCommentLayout.addView(mSlvComment);
	}

	/* (non-Javadoc)
	 * @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
	 */
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		if(resultCode == RESULT_OK)
		{
			mCommentListHandler.refreshForLast();
			setResult(RESULT_OK);
		}
	}

	/* (non-Javadoc)
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	@Override
	public void onClick(View v)
	{
		switch(v.getId())
		{
		// 대상 커뮤니티 버튼을 누른 경우 해당 커뮤니티로 이동
		case R.id.community_comment_activity_tv_community:
			Bundle extras = new Bundle();
			extras.putInt("keywordIdx", mKeywordIdx);
			getNewActivity()
				.setTargetActivity(CommunityActivity.class)
				.setBundle(extras)
				.show();
			break;
		}
	}
}